package com.ms.pda.repository

import com.blankj.utilcode.util.Utils
import com.ms.pda.db.AppDataBase
import com.ms.pda.model.table.*
import com.ms.pda.model.vo.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn

object DB : DataSource {

    /**
     * 新增出库单
     */
    suspend fun insertStorageOut(newList: MutableList<StorageOutDO>) {
        AppDataBase.getDataBase(Utils.getApp())
            .storageDao()
            .insertStorageOut(newList)
    }


    /**
     * 清除出库记录
     */
    suspend fun clearStorageOut() {
        AppDataBase.getDataBase(Utils.getApp())
            .storageDao()
            .deleteStorageOut()
    }


    /**
     * 获取未提交记录
     */
    fun queryStorageOut(orderNumber: String): Flow<List<StorageOutDO>> {
        return AppDataBase.getDataBase(Utils.getApp())
            .storageDao()
            .queryStorageOut(orderNumber)
            .flowOn(Dispatchers.IO)
    }

    /**
     * 获取未提交记录
     */
    fun queryStorageOut(): Flow<List<StorageOutDO>> {
        return AppDataBase.getDataBase(Utils.getApp())
            .storageDao()
            .queryStorageOut()
            .flowOn(Dispatchers.IO)
    }


}